package com.xxs.common.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.xxs.common.Const;
import com.xxs.utils.Context;
import com.xxs.utils.xml.Fields;
import com.xxs.utils.xml.XmlDom4jUtils;

public class BaseController extends Controller {
		//获取xml文件路径
		public String getXmlPath(boolean withSiteCode){
			if(withSiteCode){
				return getXmlPath(getCurrentSiteCode(), getModeName());
			}else{
				return Const.XML_PREFIX+getModeName()+Const.XML_SUFFIX;
			}
		}
		public String getXmlPath(String siteCode,String modelName){
			if(siteCode!=null){
				return Const.XML_PREFIX+siteCode+"/"+modelName+Const.XML_SUFFIX;
			}else{
				return Const.XML_PREFIX+modelName+Const.XML_SUFFIX;
			}
		}
		public String getXmlPath(String modelName){
			return Const.XML_PREFIX+modelName+Const.XML_SUFFIX;
		}
		
		public String getCurrentSiteCode(){
			String siteCode = XmlDom4jUtils.getParaValueByAttrAndValue(Const.SITE_PATH,"site","id",Context.getCurrentSiteId(getSession()),"code");
			return siteCode;
		}
		public String getCurrentModelName(){
			String siteCode = XmlDom4jUtils.getParaValueByAttrAndValue(Const.SITE_PATH,"site","id",Context.getCurrentSiteId(getSession()),"code");
			return siteCode;
		}
		public String getCurrentSiteName(){
			String siteName = XmlDom4jUtils.getParaValueByAttrAndValue(Const.SITE_PATH,"site","id",Context.getCurrentSiteId(getSession()),"name");
			return siteName;
		}
		
		/**
		 * 获取对象字段
		 * @param modelName
		 * @return
		 */
		public List<Fields> getFields() {
			return XmlDom4jUtils.getFields(Const.SYSTEM_TABLES_PATH,getModeName());
		}
		
		public String getModeName() {
			return getAttrForStr("modelName");
		}
}
